package com.bysj.yqsht.web.controller;

import com.bysj.yqsht.bean.Classes;
import com.bysj.yqsht.bean.extend.ClassesExtend;
import com.bysj.yqsht.service.IClassesService;
import com.bysj.yqsht.utils.Message;
import com.bysj.yqsht.utils.MessageUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/class")
@Api(description = "班级管理接口")
public class ClassesController {
    @Autowired
    private IClassesService classesService;

    @GetMapping("/findAll")
    public Message findAll(){
        List<Classes> list = classesService.findAll();
        return MessageUtil.success(list);
    }

    @GetMapping("findAllWithAll")
    public Message findAllWithTeacher(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int limit){
        List<ClassesExtend> list = classesService.findAllWithTeacher(pageNum,limit);
        return MessageUtil.success(list);
    }
    @GetMapping("findAllWithSubject")
    public List<ClassesExtend> findAllWithSubject(){
        return classesService.findAllWithSubject();
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Classes clas){
        classesService.saveOrUpdate(clas);
        return MessageUtil.success("修改或新增成功");
    }
    @GetMapping("deletaById")
    public Message deleteById(long id){
        classesService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
    @GetMapping("findWithAllByTeacher")
    public Message findWithAllByTeacher(String teacher,Long teacherId,Long subjectId){
        List<ClassesExtend> classExtends = classesService.findWithAllByTeacher(teacher,teacherId,subjectId);
        return MessageUtil.success(classExtends);
    }
}
